Skip to main content

DIDCOMM

DIDComm, which stands for "Decentralized Identifier Communication",is a set of specifications and protocols designed to enable secure and private communication between autonomous entities using Decentralized Identifiers (DIDs).

DIDComm Messaging refers to the part of DIDComm that focuses on messaging and communication between different systems and entities. Essentially, DIDComm Messaging provides a framework to allow autonomous parties to communicate securely and privately using DIDs as a basis for identification. This is crucial for building decentralized systems where entities need to communicate without relying on centralized intermediaries.

DIDComm Messaging includes specifications for message structure, end-to-end encryption, authentication, and authorization of involved parties. It also emphasizes interoperability, meaning it aims to enable different systems and platforms to consistently implement DIDComm Messaging so they can communicate with each other.

If you want to learn more about DIDComm Messaging, visit the official documentation provided by the DIF DIDComm Messaging v2.1

Ejemplo práctico

DidComm

Imagine that Alice and Bob are two individuals who want to communicate securely and privately using their Decentralized Identifiers (DIDs).

Alice shares her DID with Bob, and vice versa, allowing them to know how to communicate and how to encrypt and decrypt messages.

Alice decides to send a message to Bob. She uses her DID and Bob's DID to initiate communication.

Alice encrypts the message using the public key of Bob's DID. This ensures that only Bob can decrypt and read the message, as he is the sole possessor of the private key corresponding to his public key.

Alice sends the encrypted message through the network to Bob's DID address.

Bob's system receives the encrypted message directed to his DID.

Bob uses his private key (known only to him) to decrypt the message sent by Alice. This ensures that only Bob can read the message's content.

Bob decides to respond to Alice's message. He initiates a new communication using his DID and Alice's DID.

Bob encrypts his response using the public key of Alice's DID and sends the encrypted message back through the network.

Alice uses her private key to decrypt Bob's response and reads its content.

This example illustrates how DIDComm Messaging allows Alice and Bob to communicate securely and privately using their DIDs. The communication is end-to-end encrypted and relies on the authentication of the parties through their DIDs. The protocol enables asynchronous communication, meaning Alice and Bob don't need to be online at the same time to exchange messages.

Pack and Unpack a message

1. Install

npm i @extrimian/kms-client
npm i @extrimian/kms-core

2. Instance a KMS

const kms = new KMSClient({
lang: LANG.en,
storage: new FileSystemKMSSecureStorage({
filepath: "file-system-storage",
}),
didResolver: (did: string) => resolveDID(did),
});

3. Pack

const packedMessage = await kms.packDIDCommV2({
senderVerificationMethodId:
"did:quarkid:zksync:EiDKngDKk7dQZxSxAiDeZzVh8dAuu5jdJfgmLnmPV08heg#didComm", //Verification method from sender
recipientVerificationMethodIds: [
"did:quarkid:zksync:EiAGXcAlFpaGg870bgyU05PNSeIINqDvv__wWQ0RdtwcXQ#didComm",
], //Verification method from recipient, it could be more than one recipient
message: IDIDCommMessage, //DIDCOMM message type
packing: "authcrypt",
});

DIDCOMM Message Structure

interface IDIDCommMessage {
type: string;
from?: string;
to: string[];
thid?: string;
pthid?: string;
id: string;
expires_time?: string;
created_time?: string;
next?: string;
from_prior?: string;
body: any;
}

4. Unpack

const unpackedMsg = await kms.unpackvDIDCommV2(
"did:quarkid:zksync:EiAGXcAlFpaGg870bgyU05PNSeIINqDvv__wWQ0RdtwcXQ", //Recipient's DID
packedMessage
);